package com.youku.skin
{
   import com.youku.interfaces.ISkinChangeCompent;
   import com.youku.data.PartenerSkinData;
   import com.youku.PlayerConfig;
   import flash.filters.GlowFilter;
   import flash.filters.BitmapFilterQuality;
   import flash.filters.ColorMatrixFilter;
   
   public class PartenerSkinManager extends Object
   {
      
      public function PartenerSkinManager() {
         super();
      }
      
      public static var SETUP_BTN:String = "SETUP_BTN";
      
      public static var SETUP_TXT:String = "SETUP_TXT";
      
      public static var CONTROLBAR_BTN:String = "CONTROLBAR_BTN";
      
      public static var PROGRESSBAR_CACHED:String = "PROGRESSBAR_CACHED";
      
      public static var PROGRESSBAR_PLAYED:String = "PROGRESSBAR_PLAYED";
      
      public static var PROGRESSBAR_CACHEDLESS:String = "PROGRESSBAR_CACHEDLESS";
      
      public static var PROGRESSBAR_DOT:String = "PROGRESSBAR_DOT";
      
      public static var LOADING:String = "LOADING";
      
      public static var allRef:Vector.<ISkinChangeCompent> = new Vector.<ISkinChangeCompent>();
      
      public static function upDateAllSkin() : void {
         var _loc1_:int = allRef.length;
         var _loc2_:* = 0;
         while(_loc2_ < _loc1_)
         {
            if(allRef[_loc2_])
            {
               allRef[_loc2_].upDateSkin();
            }
            _loc2_++;
         }
      }
      
      public static function clearAllSkin() : void {
         var _loc1_:int = allRef.length;
         var _loc2_:* = 0;
         while(_loc2_ < _loc1_)
         {
            if(allRef[_loc2_])
            {
               allRef[_loc2_].clearSkin();
            }
            _loc2_++;
         }
      }
      
      public static function get skinData() : PartenerSkinData {
         return PlayerConfig.partnerData.skinData;
      }
      
      public static function push(param1:ISkinChangeCompent) : void {
         if(getCompentIndex(param1) != -1)
         {
            return;
         }
         allRef.push(param1);
      }
      
      public static function getCompentIndex(param1:ISkinChangeCompent) : int {
         var _loc2_:* = 0;
         var _loc3_:ISkinChangeCompent = null;
         _loc2_ = 0;
         while(_loc2_ < allRef.length)
         {
            _loc3_ = allRef[_loc2_];
            if(_loc3_ == param1)
            {
               return _loc2_;
            }
            _loc2_++;
         }
         return -1;
      }
      
      public static function getFilters(param1:String, param2:Boolean = false) : Array {
         var _loc3_:Array = [];
         switch(param1)
         {
            case SETUP_BTN:
               _loc3_.push(getColorMatrixFilter(skinData.setup_btn));
               break;
            case SETUP_TXT:
               _loc3_.push(getColorMatrixFilter(skinData.setup_txt));
               break;
            case CONTROLBAR_BTN:
               _loc3_.push(getColorMatrixFilter(skinData.controllbar_btn));
               break;
            case PROGRESSBAR_CACHED:
               _loc3_.push(getColorMatrixFilter(skinData.progressbar_cached));
               break;
            case PROGRESSBAR_PLAYED:
               _loc3_.push(getColorMatrixFilter(skinData.progressbar_played));
               break;
            case PROGRESSBAR_CACHEDLESS:
               _loc3_.push(getColorMatrixFilter(skinData.progressbar_cacheless));
               break;
            case PROGRESSBAR_DOT:
               _loc3_.push(getColorMatrixFilter(skinData.progressbar_dot));
               break;
            case LOADING:
               _loc3_.push(getColorMatrixFilter(skinData.setup_btn));
               break;
         }
         if(param2)
         {
            _loc3_.push(getGlowFilter());
         }
         return _loc3_;
      }
      
      private static function getGlowFilter() : GlowFilter {
         var _loc1_:GlowFilter = new GlowFilter();
         _loc1_.color = 16777215;
         _loc1_.alpha = 0.5;
         _loc1_.blurX = 2;
         _loc1_.blurY = 2;
         _loc1_.quality = BitmapFilterQuality.HIGH;
         return _loc1_;
      }
      
      private static function getColorMatrixFilter(param1:int) : ColorMatrixFilter {
         var _loc2_:Array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];
         var param1:int = param1 % 16777216;
         var _loc3_:* = 0;
         while(_loc3_ < 3)
         {
            _loc2_[14 - 5 * _loc3_] = param1 % (16 * 16);
            param1 = int(param1 / (16 * 16));
            _loc3_++;
         }
         return new ColorMatrixFilter(_loc2_);
      }
   }
}
